Multiple inheritance using interface

  • Note

    multiple inheritance using interface

    Suppose we want to add a new method to the existing interface, we can add new methods to interface. But that change will affact the all child classes

    multiple inheritance helps the developer to add new functions to the existing interface without affacting the other child classes

    Steps

    1. Create new interface

    2. add the new functions in the new interface

    3. apply the new interface to the child class you want to modify

    Example

    Existing interface: PaymentGatewayInterface
    
                        interface PaymentGatewayInterface
                        {
                            public function paymentRequest();
                            public function paymentResponse();
                        }
    
                    
    Already implemented in StripePaymentService and PaypalPaymentService
    
                         //StripePaymentService
                         class StripePaymentService implements  PaymentGatewayInterface
                         {
    
                            public function paymentRequest(){
    
                            }
    
                            public function paymentResponse(){
                                
                            }
    
    
                         } 
    
    
    
    
                         //PaypalPaymentService
                         class PaypalPaymentService implements  PaymentGatewayInterface
                         {
    
                            public function paymentRequest(){
    
                            }
    
                            public function paymentResponse(){
                                
                            }
    
    
                         } 
    
                    
    We want to implement a new function refundPayment() in StripePaymentService

    Create new interface "RefundInterface"

    
    
                        interface RefundInterface{
                            public function refundPayment();
                            
                        }
    
                    

    implement the new interface in StripePaymentService

    
                         //StripePaymentService
                         class StripePaymentService implements  PaymentGatewayInterface, RefundInterface
                         {
    
                            public function paymentRequest(){
    
                            }
    
                            public function paymentResponse(){
                                
                            }
    
                            public function refundPayment(){
                                
                            }
    
    
    
                         }